let loadingInstance = null

let plugin = {
    sucMes(vue, text) {
        vue.$message.success(text)
    },

    loading(vue, text) {
        loadingInstance = vue.$loading({
            lock: true,
            text,
            spinner: "el-icon-loading",
            background: "rgba(0, 0, 0, 0.7)",
        })
    },

    closeLoading() {
        loadingInstance.close();
    },

    loadInstance() {
        return loadingInstance
    },

    confirm(func, text, success, error = () => { }) {
        return func(text, '系统提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(success)
            .catch(error)

    },

    prompt({ func, text, errMes }, validFunc, success, error = () => { }) {
        return func(text, '系统提示',
            {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                inputValidator: validFunc,
                inputErrorMessage: errMes,
            }).then(success)
            .catch(error)
    },

    checkForm(vm, formName) {
        let end = false
        vm.$refs[formName].validate((valid) => {
            end = valid
        })
        return end
    },

}

export default plugin